package com.jane.adapter.homepageadapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jane.adapter.MyBaseAdapter;
import com.jane.bean.HomePageGridViewBean;
import com.jane.gzzb.R;
import com.jane.utils.Utils;

import java.util.List;

/**
 * Created by Administrator on 2016/11/15.
 */

public class LiveDataAdapter extends MyBaseAdapter {
    //申明
    private Context mContext;
    private LayoutInflater mInflater;

    public LiveDataAdapter(Context context, List Data) {
        super(Data);
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_list_live_tablayout, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //获取数据
        HomePageGridViewBean data = (HomePageGridViewBean) getItem(position);
        Utils.loadCircleImage(holder.rawcommentatorimage, data.getRawcommentatorimage());
        holder.position.setText((position + 4) + "");
        holder.commentator.setText(data.getCommentator());
        holder.name.setText(data.getName());
        holder.renqi.setText("人气" + data.getRenqi());
        holder.guanzhu.setTag(position);
        holder.guanzhu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.guanzhu.setText("已关注");
                holder.guanzhu.setTextColor(Color.GRAY);
            }
        });
        return convertView;
    }

    public static class ViewHolder {
        ImageView rawcommentatorimage;
        TextView position, commentator, name, renqi, guanzhu;

        public ViewHolder(View convertView) {
            rawcommentatorimage = (ImageView) convertView.findViewById(R.id.item_list_tablayout_rawcommentatorimage);
            position = (TextView) convertView.findViewById(R.id.item_list_tablayout_position);
            commentator = (TextView) convertView.findViewById(R.id.item_list_tablayout_commentator);
            name = (TextView) convertView.findViewById(R.id.item_list_tablayout_name);
            renqi = (TextView) convertView.findViewById(R.id.item_list_tablayout_renqi);
            guanzhu = (TextView) convertView.findViewById(R.id.item_list_tablayout_guanzhu);
        }
    }
}
